home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / CALLDBD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  2.5 KB  |  115 lines

  1. /* Callbook server */
  2. /* Mods by KO4KS */
  3. #include "global.h"
  4. #include "commands.h"
  5. #include "files.h"
  6. #include "mbuf.h"
  7. #include "socket.h"
  8. #include "session.h"
  9. #include "mailbox.h"
  10.  
  11. #if !defined(_lint)
  12. static char rcsid[] OPTIONAL = "$Id: calldbd.c,v 1.17 1997/08/19 01:19:22 root Exp root $";
  13. #endif
  14.  
  15. #if defined(CALLBOOK) || defined(CALLSERVER) || defined(SAMCALLB) || defined(QRZCALLB)
  16.  
  17. extern char *Callserver;    /* buckbook.c */
  18.  
  19. int Scallbook = -1;        /* Prototype socket for service */
  20.  
  21. static void calldbd (int s, void *unused, void *p);
  22.  
  23.  
  24. #if defined(SAMCALLB) || defined(QRZCALLB)
  25. extern int cb_lookup (int s, char *call, FILE * fp);
  26. #else
  27. extern void cb_lookup (int s, char *call);    /* in buckbook.c  */
  28. #endif
  29.  
  30.  
  31. /* Start up callsign database service */
  32. int
  33. cdbstart (argc, argv, p)
  34. int argc;
  35. char *argv[];
  36. void *p OPTIONAL;
  37. {
  38.     return (installserver (argc, argv, &Scallbook, "Callbook listener", IPPORT_CALLDB,
  39.         INADDR_ANY, "calldbd", calldbd, 1024, NULL));
  40. }
  41.  
  42.  
  43. static void
  44. calldbd (s, unused, p)
  45. int s;
  46. void *unused OPTIONAL;
  47. void *p OPTIONAL;
  48. {
  49. char user[80];
  50. #if defined(SAMCALLB) || defined(QRZCALLB)
  51. int err;
  52. #endif
  53.  
  54.     (void) sockmode (s, SOCK_ASCII);
  55.     (void) sockowner (s, Curproc);
  56.     if (recvline (s, (unsigned char *) user, 80) == -1)
  57.         return;
  58.     rip (user);
  59.     log (s, "Callbook lookup: %s", user);
  60.     if (strlen (user) == 0)
  61.         usputs (s, "No Callbook information available\n");
  62.     else {
  63. #if defined(SAMCALLB) || defined(QRZCALLB)
  64.         if ((err = cb_lookup (s, user, (FILE *) 0)) != 0)
  65.             usputs (s, (err == 2) ? "No Callbook information available\n" : "Callbook not active\n");
  66. #else
  67.         cb_lookup (s, user);
  68. #endif
  69.     }
  70.     close_s (s);
  71. }
  72.  
  73.  
  74. int
  75. cdb0 (argc, argv, p)
  76. int argc OPTIONAL;
  77. char *argv[] OPTIONAL;
  78. void *p OPTIONAL;
  79. {
  80.     return (deleteserver (&Scallbook));
  81. }
  82.  
  83. #endif
  84.  
  85.  
  86.  
  87. /* This routine has been expanded upon, and is now located in buckbook.c
  88.   - kb7yw Mon  01-27-1992   - except if using the SAM database - ko4ks */
  89.  
  90. #if defined(CALLCLI) || defined(SAMCALLB) || defined(QRZCALLB)
  91. char *Callserver;
  92.  
  93. int
  94. docallserver (argc, argv, p)
  95. int argc;
  96. char *argv[];
  97. void *p OPTIONAL;
  98. {
  99.     if (argc < 2) {
  100.         if (Callserver != NULLCHAR)
  101.             tprintf ("The callserver's host name is: %s\n", Callserver);
  102.         else {
  103.             tputs ("Callserver not configured!\n");
  104.             tputs ("Usage: callserver hostname OR callserver ip_address\n");
  105.         }
  106.     } else {
  107.         if (Callserver != NULLCHAR)
  108.             free (Callserver);
  109.         Callserver = strdup (argv[1]);
  110.     }
  111.     return 0;
  112. }
  113.  
  114. #endif
  115.